package 第四章类与对象.员工类;

import java.time.LocalDate;
import java.util.Objects;

public class Manager extends Employee {
    private double bonus;

    public Manager() {
    }

    public Manager(String name, double salary, LocalDate hireDay, double bonus) {
        super(name, salary, hireDay);
        this.bonus = bonus;
    }

    public double getBonus() {
        return bonus;
    }

    public void setBonus(double bonus) {
        this.bonus = bonus;
    }

    //重写父类中的getSalary方法；
    @Override
    public double getSalary() {
        double baseSalary = super.getSalary();
        return baseSalary + bonus;
    }

    @Override
    public boolean equals(Object obj) {

        //先进行父类的equals方法的判断；
        //如果返回的是false就返回一个false，如果返回true就对子类独有的字段进行比较；
        ;if(!super.equals(obj)){
            return false;
        }

        //将比较的对象强转为子类的对象；
        //因为在父类的equals方法中已经比较过两者的类型是否相等了，所以可以直接强转；
        Manager manager = (Manager) obj;
        //比较子类独有的字段；
        return this.bonus == manager.bonus;

    }
}
